package com.opengroupe.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.opengroupe.R;
import com.opengroupe.dto.SingleQuestionReponse;

public class SingleQuestionReponseArrayAdapter extends ArrayAdapter<SingleQuestionReponse> {

	private Context context = null;

	public SingleQuestionReponseArrayAdapter(Context context, List<SingleQuestionReponse> singleQuestionReponses) {
		
		super(context, R.layout.resultat_layout, singleQuestionReponses);
		
	    this.context = context;
	}
	
	@Override
	  public View getView(int position, View convertView, ViewGroup parent) {
		
		View rowView = convertView;
		
		if (rowView  == null)
		{
			LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			rowView = inflater.inflate(R.layout.resultat_layout, parent, false);
		}
		
		if (rowView.getTag() != null) return rowView;
		
		SingleQuestionReponse question = this.getItem(position);
		
		rowView.setTag(question);
		
		//txtContenuQuestion
	    TextView txtContenuQuestion = (TextView) rowView.findViewById(R.id.txtContenuQuestion);
	    txtContenuQuestion.setText(question.getQuestion().getContenuQuestion());
	    
	    // imgResultat
	    ImageView imageView = (ImageView) rowView.findViewById(R.id.imgResultat);
	    if (question.questionCorrecte()){
	      imageView.setImageResource(R.drawable.tick);
	    } else {
	      imageView.setImageResource(R.drawable.cross);
	    }

	    return rowView;
	  }
}
